<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>通用规则生成器 - 白嫖者联盟</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary: #ff7e5f;
            --secondary: #feb47b;
            --dark: #0f2027;
            --darker: #0a151c;
            --light: #e0e0e0;
            --card-bg: rgba(25, 30, 50, 0.8);
            --success: #28a745;
            --warning: #ffc107;
            --danger: #dc3545;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, var(--darker), var(--dark));
            color: var(--light);
            min-height: 100vh;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        .container {
            max-width: 1200px;
            width: 100%;
            margin: 0 auto;
        }
        
        header {
            text-align: center;
            padding: 30px 0;
            margin-bottom: 20px;
            position: relative;
            width: 100%;
        }
        
        .logo {
            font-size: 3.5rem;
            color: var(--primary);
            margin-bottom: 15px;
            text-shadow: 0 0 15px rgba(255, 126, 95, 0.7);
        }
        
        h1 {
            font-size: 2.8rem;
            margin-bottom: 10px;
            background: linear-gradient(to right, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
        }
        
        .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
            max-width: 800px;
            margin: 0 auto;
            line-height: 1.6;
            color: #b0d4ff;
        }
        
        .generator-container {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 25px;
            margin-bottom: 30px;
        }
        
        @media (max-width: 992px) {
            .generator-container {
                grid-template-columns: 1fr;
            }
        }
        
        .card {
            background: var(--card-bg);
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 25px;
        }
        
        .card-header {
            padding: 18px 25px;
            background: rgba(40, 45, 70, 0.9);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .card-title {
            font-size: 1.4rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .card-title i {
            color: var(--primary);
        }
        
        .card-body {
            padding: 25px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: var(--secondary);
        }
        
        input, textarea, select {
            width: 100%;
            padding: 12px 15px;
            border-radius: 8px;
            border: 1px solid rgba(255, 255, 255, 0.2);
            background: rgba(20, 25, 45, 0.7);
            color: white;
            font-size: 1rem;
        }
        
        textarea {
            min-height: 120px;
            font-family: monospace;
        }
        
        .checkbox-group {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 15px 0;
        }
        
        .btn {
            padding: 12px 25px;
            border-radius: 8px;
            border: none;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .btn-primary {
            background: linear-gradient(to right, var(--primary), var(--secondary));
            color: white;
            box-shadow: 0 5px 15px rgba(255, 126, 95, 0.4);
        }
        
        .btn-primary:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(255, 126, 95, 0.6);
        }
        
        .btn-secondary {
            background: rgba(255, 255, 255, 0.1);
            color: #fff;
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .btn-secondary:hover {
            background: rgba(255, 255, 255, 0.2);
        }
        
        .btn-container {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 25px;
        }
        
        .code-block {
            background: #1e1e1e;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-family: 'Fira Code', monospace;
            font-size: 0.95rem;
            line-height: 1.5;
            max-height: 500px;
            overflow-y: auto;
        }
        
        .code-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 15px;
            color: var(--secondary);
        }
        
        .code-toolbar {
            display: flex;
            gap: 10px;
        }
        
        .code-btn {
            background: rgba(255, 255, 255, 0.1);
            border: none;
            color: #fff;
            padding: 7px 15px;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        
        .code-btn:hover {
            background: rgba(255, 255, 255, 0.2);
        }
        
        .token {
            color: #569cd6;
        }
        
        .string {
            color: #ce9178;
        }
        
        .comment {
            color: #6a9955;
        }
        
        .status-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 15px;
            margin-bottom: 20px;
        }
        
        .status-item {
            padding: 15px;
            background: rgba(30, 35, 55, 0.6);
            border-radius: 10px;
        }
        
        .status-label {
            font-weight: 600;
            margin-bottom: 8px;
            display: flex;
            align-items: center;
            gap: 8px;
            color: #b0d4ff;
        }
        
        .status-value {
            padding: 8px 12px;
            border-radius: 8px;
            background: rgba(20, 25, 45, 0.7);
            font-family: monospace;
            word-break: break-all;
        }
        
        .rule-preview {
            margin-top: 25px;
            padding-top: 20px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .preview-title {
            font-size: 1.3rem;
            margin-bottom: 15px;
            color: var(--secondary);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .instructions {
            background: rgba(30, 35, 55, 0.6);
            border-radius: 10px;
            padding: 20px;
            margin-top: 20px;
        }
        
        .instructions h3 {
            color: var(--secondary);
            margin-bottom: 15px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .instructions ul {
            padding-left: 25px;
            line-height: 1.8;
        }
        
        .instructions li {
            margin-bottom: 10px;
        }
        
        footer {
            text-align: center;
            padding: 30px 0;
            margin-top: 40px;
            color: rgba(255, 255, 255, 0.6);
            font-size: 0.9rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="logo">
                <i class="fas fa-crown"></i>
            </div>
            <h1>通用规则生成器</h1>
            <p class="subtitle">白嫖者联盟 | 自定义规则配置与自动Cookie预处理</p>
        </header>
        
        <div class="generator-container">
            <div class="card">
                <div class="card-header">
                    <h2 class="card-title">
                        <i class="fas fa-sliders-h"></i> 规则配置
                    </h2>
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label for="ruleTitle"><i class="fas fa-heading"></i> 规则标题</label>
                        <input type="text" id="ruleTitle" value="白嫖者联盟">
                    </div>
                    
                    <div class="form-group">
                        <label for="ruleTemplate"><i class="fas fa-layer-group"></i> 模板类型</label>
                        <select id="ruleTemplate">
                            <option value="首图">首图</option>
                            <option value="列表">列表</option>
                            <option value="详情">详情</option>
                            <option value="瀑布流">瀑布流</option>
                        </select>
                    </div>
                    
                    <div class="form-group">
                        <label for="ruleHost"><i class="fas fa-globe"></i> 网站域名</label>
                        <input type="text" id="ruleHost" value="https://www.qyzf88.com">
                    </div>
                    
                    <div class="form-group">
                        <label for="ruleUrl"><i class="fas fa-link"></i> 内容URL</label>
                        <input type="text" id="ruleUrl" value="/qyvodtype/fyclass-fypage.html">
                    </div>
                    
                    <div class="form-group">
                        <label for="searchUrl"><i class="fas fa-search"></i> 搜索URL</label>
                        <input type="text" id="searchUrl" value="/qyvodsearch/**----------fypage---.html">
                    </div>
                    
                    <div class="form-group">
                        <label for="classParse"><i class="fas fa-code-branch"></i> 分类解析规则</label>
                        <input type="text" id="classParse" value=".myui-header__menu li:gt(0):lt(5);a&&Text;a&&href;/(\\d+).html">
                    </div>
                    
                    <div class="checkbox-group">
                        <input type="checkbox" id="searchable" checked>
                        <label for="searchable">可搜索</label>
                    </div>
                    
                    <div class="checkbox-group">
                        <input type="checkbox" id="filterable">
                        <label for="filterable">可筛选</label>
                    </div>
                    
                    <div class="form-group">
                        <label for="defaultCookie"><i class="fas fa-cookie"></i> 默认Cookie</label>
                        <input type="text" id="defaultCookie" value="3d1899503da128319d46484900974d61=2260e8918a83e15f322f083e71586517">
                    </div>
                    
                    <div class="form-group">
                        <label for="preprocessCode"><i class="fas fa-cog"></i> 预处理代码</label>
                        <textarea id="preprocessCode">(function() {
    // 尝试从存储获取历史Cookie
    var savedCookie = typeof getItem === 'function' ? getItem('RULE_CK') : '';
    if (savedCookie) {
        rule_fetch_params.headers.Cookie = savedCookie;
        return;
    }
    
    // 初始化默认Cookie
    var defaultCookie = "DEFAULT_COOKIE";
    rule_fetch_params.headers.Cookie = defaultCookie;
    
    try {
        // 首次检测请求
        var new_html = request(rule.host);
        
        // 情况1: 检测中
        if (/检测中/.test(new_html)) {
            var headerResponse = request(rule.host, { withHeaders: true });
            var headerJson = JSON.parse(headerResponse);
            var setCookieKey = Object.keys(headerJson).find(function(k) {
                return k.toLowerCase() === "set-cookie";
            });
            
            if (setCookieKey) {
                var cookieValue = headerJson[setCookieKey].split(";")[0];
                rule_fetch_params.headers.Cookie = cookieValue;
                if (typeof setItem === 'function') {
                    setItem('RULE_CK', cookieValue);
                }
            }
        }
        // 情况2: 人机验证
        else if (/正在进行人机识别/.test(new_html)) {
            // 提取验证脚本URL
            var scriptMatch = new_html.match(/<script[^>]*src=["']([^"']+)["']/i);
            var scriptSrc = scriptMatch ? scriptMatch[1] : '';
            
            if (scriptSrc) {
                // 确保URL完整
                if (!scriptSrc.startsWith('http')) {
                    scriptSrc = rule.host + (scriptSrc.startsWith('/') ? scriptSrc : '/' + scriptSrc);
                }
                
                // 获取验证脚本
                var scriptResponse = request(scriptSrc, { withHeaders: true });
                var scriptData = JSON.parse(scriptResponse);
                var scriptContent = scriptData.body || '';
                
                // 提取验证参数
                var keyMatch = scriptContent.match(/var key="([^"]+)"/);
                var valueMatch = scriptContent.match(/value="([^"]+)"/);
                var key = keyMatch ? keyMatch[1] : '';
                var avalue = valueMatch ? valueMatch[1] : '';
                
                if (key && avalue) {
                    // 生成验证码
                    var charCodes = '';
                    for (var i = 0; i < avalue.length; i++) {
                        charCodes += avalue.charCodeAt(i);
                    }
                    var value = md5(charCodes);
                    
                    // 执行验证请求
                    var verifyUrl = rule.host + "/a20be899_96a6_40b2_88ba_32f1f75f1552_yanzheng_ip.php?type=96c4e20a0e951f471d32dae103e83881&key=" + key + "&value=" + value;
                    var verifyResponse = request(verifyUrl, { withHeaders: true });
                    var verifyData = JSON.parse(verifyResponse);
                    
                    // 更新Cookie
                    var verifyCookieKey = Object.keys(verifyData).find(function(k) {
                        return k.toLowerCase() === "set-cookie";
                    });
                    
                    if (verifyCookieKey) {
                        var newCookie = verifyData[verifyCookieKey].split(";")[0];
                        rule_fetch_params.headers.Cookie = newCookie;
                        if (typeof setItem === 'function') {
                            setItem('RULE_CK', newCookie);
                        }
                    }
                }
            }
        }
    } catch (e) {
        // 出错时使用默认Cookie
        rule_fetch_params.headers.Cookie = defaultCookie;
    }
})()</textarea>
                    </div>
                    
                    <div class="btn-container">
                        <button class="btn btn-primary" id="generateBtn">
                            <i class="fas fa-cogs"></i> 生成规则代码
                        </button>
                        <button class="btn btn-secondary" id="resetBtn">
                            <i class="fas fa-redo"></i> 重置配置
                        </button>
                    </div>
                </div>
            </div>
            
            <div class="card">
                <div class="card-header">
                    <h2 class="card-title">
                        <i class="fas fa-code"></i> 规则代码
                    </h2>
                </div>
                <div class="card-body">
                    <div class="status-container">
                        <div class="status-item">
                            <div class="status-label">
                                <i class="fas fa-cookie-bite"></i> Cookie状态
                            </div>
                            <div class="status-value">
                                自动获取: 已启用
                            </div>
                        </div>
                        
                        <div class="status-item">
                            <div class="status-label">
                                <i class="fas fa-shield-alt"></i> 验证处理
                            </div>
                            <div class="status-value">
                                双重检测机制
                            </div>
                        </div>
                        
                        <div class="status-item">
                            <div class="status-label">
                                <i class="fas fa-database"></i> 存储机制
                            </div>
                            <div class="status-value">
                                getItem/setItem
                            </div>
                        </div>
                        
                        <div class="status-item">
                            <div class="status-label">
                                <i class="fas fa-plug"></i> 依赖函数
                            </div>
                            <div class="status-value">
                                request(), md5()
                            </div>
                        </div>
                    </div>
                    
                    <div class="code-block" id="outputCode">
                        <div class="code-header">
                            <div>生成的规则代码将显示在这里</div>
                            <div class="code-toolbar">
                                <button class="code-btn" id="copyCodeBtn">
                                    <i class="fas fa-copy"></i> 复制
                                </button>
                                <button class="code-btn" id="downloadBtn">
                                    <i class="fas fa-download"></i> 下载
                                </button>
                            </div>
                        </div>
                        <pre id="codeContent"><span class="comment">// 配置规则并点击"生成规则代码"</span></pre>
                    </div>
                    
                    <div class="rule-preview">
                        <div class="preview-title">
                            <i class="fas fa-eye"></i> 规则预览
                        </div>
                        <div class="status-container">
                            <div class="status-item">
                                <div class="status-label">标题</div>
                                <div class="status-value" id="previewTitle">-</div>
                            </div>
                            <div class="status-item">
                                <div class="status-label">域名</div>
                                <div class="status-value" id="previewHost">-</div>
                            </div>
                            <div class="status-item">
                                <div class="status-label">内容URL</div>
                                <div class="status-value" id="previewUrl">-</div>
                            </div>
                            <div class="status-item">
                                <div class="status-label">搜索功能</div>
                                <div class="status-value" id="previewSearch">-</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h2 class="card-title">
                    <i class="fas fa-info-circle"></i> 使用说明
                </h2>
            </div>
            <div class="card-body">
                <div class="instructions">
                    <h3><i class="fas fa-book"></i> 通用规则生成指南</h3>
                    <ul>
                        <li><strong>标题</strong>：设置规则的显示名称</li>
                        <li><strong>模板类型</strong>：选择适合的展示模板（首图、列表等）</li>
                        <li><strong>网站域名</strong>：目标网站的主域名（https://开头）</li>
                        <li><strong>内容URL</strong>：内容页面的URL模式（可使用fyclass/fypage变量）</li>
                        <li><strong>搜索URL</strong>：搜索功能的URL模式（使用**作为搜索关键词占位符）</li>
                        <li><strong>分类解析规则</strong>：使用CSS选择器提取分类信息</li>
                        <li><strong>预处理代码</strong>：自动处理Cookie和验证的核心逻辑（可自定义修改）</li>
                    </ul>
                </div>
                
                <div class="instructions">
                    <h3><i class="fas fa-lightbulb"></i> 高级配置技巧</h3>
                    <ul>
                        <li>在预处理代码中使用 <code>rule.host</code> 访问配置的域名</li>
                        <li>修改正则表达式可以适配不同网站的验证机制</li>
                        <li><code>DEFAULT_COOKIE</code> 将被自动替换为设置的默认Cookie</li>
                        <li>保存的Cookie键名可在预处理代码中修改（默认'RULE_CK'）</li>
                        <li>确保执行环境提供 <code>request()</code> 和 <code>md5()</code> 函数</li>
                    </ul>
                </div>
                
                <div class="btn-container">
                    <button class="btn btn-primary">
                        <i class="fas fa-book"></i> 查看完整文档
                    </button>
                    <button class="btn btn-secondary">
                        <i class="fab fa-github"></i> 获取示例规则
                    </button>
                </div>
            </div>
        </div>
        
        <footer>
            <p>© 2023 白嫖者联盟 | 通用规则生成器 | 版本 2.1.0</p>
            <p style="margin-top: 10px; font-size: 0.8rem;">
                <i class="fas fa-exclamation-triangle"></i> 免责声明：本工具仅用于技术研究，请遵守相关法律法规
            </p>
        </footer>
    </div>

    <script>
        // 初始化页面
        document.addEventListener('DOMContentLoaded', function() {
            // 绑定生成按钮事件
            document.getElementById('generateBtn').addEventListener('click', generateRule);
            
            // 绑定重置按钮事件
            document.getElementById('resetBtn').addEventListener('click', function() {
                if(confirm('确定要重置所有配置吗？')) {
                    document.getElementById('ruleTitle').value = '白嫖者联盟';
                    document.getElementById('ruleTemplate').value = '首图';
                    document.getElementById('ruleHost').value = 'https://www.qyzf88.com';
                    document.getElementById('ruleUrl').value = '/qyvodtype/fyclass-fypage.html';
                    document.getElementById('searchUrl').value = '/qyvodsearch/**----------fypage---.html';
                    document.getElementById('classParse').value = '.myui-header__menu li:gt(0):lt(5);a&&Text;a&&href;/(\\d+).html';
                    document.getElementById('searchable').checked = true;
                    document.getElementById('filterable').checked = false;
                    document.getElementById('defaultCookie').value = '3d1899503da128319d46484900974d61=2260e8918a83e15f322f083e71586517';
                    
                    // 重置预处理代码为默认值
                    document.getElementById('preprocessCode').value = `(function() {
    // 尝试从存储获取历史Cookie
    var savedCookie = typeof getItem === 'function' ? getItem('RULE_CK') : '';
    if (savedCookie) {
        rule_fetch_params.headers.Cookie = savedCookie;
        return;
    }
    
    // 初始化默认Cookie
    var defaultCookie = "DEFAULT_COOKIE";
    rule_fetch_params.headers.Cookie = defaultCookie;
    
    try {
        // 首次检测请求
        var new_html = request(rule.host);
        
        // 情况1: 检测中
        if (/检测中/.test(new_html)) {
            var headerResponse = request(rule.host, { withHeaders: true });
            var headerJson = JSON.parse(headerResponse);
            var setCookieKey = Object.keys(headerJson).find(function(k) {
                return k.toLowerCase() === "set-cookie";
            });
            
            if (setCookieKey) {
                var cookieValue = headerJson[setCookieKey].split(";")[0];
                rule_fetch_params.headers.Cookie = cookieValue;
                if (typeof setItem === 'function') {
                    setItem('RULE_CK', cookieValue);
                }
            }
        }
        // 情况2: 人机验证
        else if (/正在进行人机识别/.test(new_html)) {
            // 提取验证脚本URL
            var scriptMatch = new_html.match(/<script[^>]*src=["']([^"']+)["']/i);
            var scriptSrc = scriptMatch ? scriptMatch[1] : '';
            
            if (scriptSrc) {
                // 确保URL完整
                if (!scriptSrc.startsWith('http')) {
                    scriptSrc = rule.host + (scriptSrc.startsWith('/') ? scriptSrc : '/' + scriptSrc);
                }
                
                // 获取验证脚本
                var scriptResponse = request(scriptSrc, { withHeaders: true });
                var scriptData = JSON.parse(scriptResponse);
                var scriptContent = scriptData.body || '';
                
                // 提取验证参数
                var keyMatch = scriptContent.match(/var key="([^"]+)"/);
                var valueMatch = scriptContent.match(/value="([^"]+)"/);
                var key = keyMatch ? keyMatch[1] : '';
                var avalue = valueMatch ? valueMatch[1] : '';
                
                if (key && avalue) {
                    // 生成验证码
                    var charCodes = '';
                    for (var i = 0; i < avalue.length; i++) {
                        charCodes += avalue.charCodeAt(i);
                    }
                    var value = md5(charCodes);
                    
                    // 执行验证请求
                    var verifyUrl = rule.host + "/a20be899_96a6_40b2_88ba_32f1f75f1552_yanzheng_ip.php?type=96c4e20a0e951f471d32dae103e83881&key=" + key + "&value=" + value;
                    var verifyResponse = request(verifyUrl, { withHeaders: true });
                    var verifyData = JSON.parse(verifyResponse);
                    
                    // 更新Cookie
                    var verifyCookieKey = Object.keys(verifyData).find(function(k) {
                        return k.toLowerCase() === "set-cookie";
                    });
                    
                    if (verifyCookieKey) {
                        var newCookie = verifyData[verifyCookieKey].split(";")[0];
                        rule_fetch_params.headers.Cookie = newCookie;
                        if (typeof setItem === 'function') {
                            setItem('RULE_CK', newCookie);
                        }
                    }
                }
            }
        }
    } catch (e) {
        // 出错时使用默认Cookie
        rule_fetch_params.headers.Cookie = defaultCookie;
    }
})()`;
                    
                    // 重置输出区域
                    document.getElementById('codeContent').innerHTML = '<span class="comment">// 配置规则并点击"生成规则代码"</span>';
                    
                    // 重置预览
                    document.querySelectorAll('#previewTitle, #previewHost, #previewUrl, #previewSearch').forEach(el => {
                        el.textContent = '-';
                    });
                }
            });
            
            // 绑定复制按钮事件
            document.getElementById('copyCodeBtn').addEventListener('click', function() {
                const code = document.getElementById('codeContent').innerText;
                copyToClipboard(code);
                
                const originalText = this.innerHTML;
                this.innerHTML = '<i class="fas fa-check"></i> 已复制';
                setTimeout(() => {
                    this.innerHTML = originalText;
                }, 2000);
            });
            
            // 绑定下载按钮事件
            document.getElementById('downloadBtn').addEventListener('click', function() {
                const code = document.getElementById('codeContent').innerText;
                const blob = new Blob([code], {type: 'application/javascript'});
                const url = URL.createObjectURL(blob);
                
                const a = document.createElement('a');
                a.href = url;
                a.download = 'rule_' + document.getElementById('ruleTitle').value + '.js';
                document.body.appendChild(a);
                a.click();
                
                setTimeout(() => {
                    document.body.removeChild(a);
                    window.URL.revokeObjectURL(url);
                }, 100);
            });
            
            // 初始生成一次
            generateRule();
        });
        
        // 生成规则代码
        function generateRule() {
            // 获取表单值
            const title = document.getElementById('ruleTitle').value;
            const template = document.getElementById('ruleTemplate').value;
            const host = document.getElementById('ruleHost').value;
            const url = document.getElementById('ruleUrl').value;
            const searchUrl = document.getElementById('searchUrl').value;
            const classParse = document.getElementById('classParse').value;
            const searchable = document.getElementById('searchable').checked ? 2 : 0;
            const filterable = document.getElementById('filterable').checked ? 1 : 0;
            const defaultCookie = document.getElementById('defaultCookie').value;
            let preprocessCode = document.getElementById('preprocessCode').value;
            
            // 更新预览
            document.getElementById('previewTitle').textContent = title;
            document.getElementById('previewHost').textContent = host;
            document.getElementById('previewUrl').textContent = url;
            document.getElementById('previewSearch').textContent = searchable ? '启用' : '禁用';
            
            // 替换预处理代码中的默认Cookie
            preprocessCode = preprocessCode.replace(/DEFAULT_COOKIE/g, defaultCookie);
            
            // 生成规则代码
            const ruleCode = `var rule = {
    title: '${title}',
    模板: '${template}',
    host: '${host}',
    url: '${url}',
    searchUrl: '${searchUrl}',
    searchable: ${searchable},
    filterable: ${filterable},
    class_parse: '${classParse}',
    
    // 自动获取Cookie的预处理逻辑
    预处理: \`${preprocessCode}\`
};`;
            
            // 高亮显示代码
            const highlightedCode = ruleCode
                .replace(/var/g, '<span class="token">var</span>')
                .replace(/function/g, '<span class="token">function</span>')
                .replace(/return/g, '<span class="token">return</span>')
                .replace(/if/g, '<span class="token">if</span>')
                .replace(/else/g, '<span class="token">else</span>')
                .replace(/try/g, '<span class="token">try</span>')
                .replace(/catch/g, '<span class="token">catch</span>')
                .replace(/typeof/g, '<span class="token">typeof</span>')
                .replace(/for/g, '<span class="token">for</span>')
                .replace(/in/g, '<span class="token">in</span>')
                .replace(/(\/\/.*)/g, '<span class="comment">$1</span>')
                .replace(/(\'.*?\')/g, '<span class="string">$1</span>');
            
            // 输出到页面
            document.getElementById('codeContent').innerHTML = highlightedCode;
        }
        
        // 复制到剪贴板
        function copyToClipboard(text) {
            const textArea = document.createElement('textarea');
            textArea.value = text;
            document.body.appendChild(textArea);
            textArea.select();
            document.execCommand('copy');
            document.body.removeChild(textArea);
        }
    </script>
</body>
</html>